package com.deploy.demo.controller;

import com.deploy.demo.annotation.PublicAccess;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;

/**
 * 健康检查控制器
 */
@Slf4j
@RestController
@Tag(name = "健康检查", description = "应用健康检查接口")
public class HealthCheckController {

    /**
     * 健康检查端点
     * 访问地址: http://localhost:${APP_PORT}/healthcheck
     */
    @PublicAccess("健康检查端点，无需认证")
    @GetMapping("/healthcheck")
    @Operation(summary = "健康检查", description = "用于检查应用是否正常运行")
    public ResponseEntity<Map<String, Object>> healthCheck() {
        log.debug("健康检查被调用");
        
        Map<String, Object> response = new HashMap<>();
        response.put("status", "UP");
        response.put("message", "Application is running");
        response.put("timestamp", LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
        
        return ResponseEntity.ok(response);
    }
}
